home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / text / faqs / g++-faq.plain < prev    next >
Encoding:
Internet Message Format  |  1994-05-17  |  41.9 KB

  1. Subject: FAQ for g++ and libg++, plain text version [Revised 15 May 1994]
  2. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  3. From: jbuck@synopsys.com (Joe Buck)
  4. Date: Sun, 15 May 1994 13:00:35 GMT
  5.  
  6. Archive-name: g++-FAQ/plain
  7. Last-modified: 15 May 1994
  8. Frequency: bimonthly
  9.  
  10. [ this is the plain text version, the parent is the texinfo version ]
  11.  
  12.  
  13. Preface
  14. *******
  15.  
  16.    This is a list of frequently asked questions (FAQ) for g++ users;
  17. thanks to all those who sent suggestions for improvements.  Thanks to
  18. Marcus Speh for doing the index.
  19.  
  20.    Many FAQ's, including this one, are available on the archive site
  21. rtfm.mit.edu, in the directory `pub/usenet/news.answers'.  This FAQ may
  22. be found in the subdirectory g++-FAQ.
  23.  
  24.    Some information in this FAQ was developed for earlier versions of
  25. the compiler and may now be obsolete.  Please send corrections.
  26.  
  27.    I'm looking for new questions (*with* answers), better answers, or
  28. both.  You can mail comments, suggestions, flames, etc. to
  29. jbuck@synopsys.com.  Please don't assume, though, that because my name
  30. is on this thing that I am the world expert on g++/C++ and you should
  31. mail all your tricky questions to me.  I'd like to be helpful but I'm
  32. getting more of this than I can deal with lately.  Also please don't
  33. assume that I am an official spokesman for g++, FSF, or Cygnus; I'm not.
  34.  
  35.    This FAQ is intended to supplement, not replace, Marshall Cline's
  36. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  37. Especially if g++ is the first C++ compiler you've ever used, the
  38. question "How do I do <X> with g++?" is probably really "How do I do
  39. <X> in C++?".  You can obtain the C++ FAQ by anonymous FTP from
  40. sun.soe.clarkson.edu [128.153.12.3], in the file `~ftp/pub/C++/FAQ'.
  41. (There is also a mail server for that FAQ, but it seems to be broken).
  42.  
  43.  
  44. Obtaining Source Code
  45. *********************
  46.  
  47.  
  48. How do I get a copy of g++ for Unix?
  49. ====================================
  50.  
  51.    First, you may already have it if you have gcc for your platform;
  52. g++ and gcc are combined now (as of gcc version 2.0).
  53.  
  54.    You can get g++ from a friend who has a copy, by anonymous FTP or
  55. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  56.  
  57.    The Free Software Foundation is a nonprofit organization that
  58. distributes software and manuals to raise funds for more GNU
  59. development.  Getting your copy from the FSF contributes directly to
  60. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  61. organization is buying, or $100 if an individual is buying.  Tapes cost
  62. around $200 depending on media type.  I recommend asking for version 2,
  63. not version 1, of g++.
  64.  
  65.    For more information about ordering from the FSF, contact
  66. gnu@prep.ai.mit.edu, phone (617) 876-3296 or anonymous ftp file
  67. `/pub/gnu/GNUinfo/ORDERS' from prep.ai.mit.edu or one of the sites
  68. listed below.
  69.  
  70.    Here is a list of anonymous FTP archive sites for GNU software.
  71.  
  72.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  73.           cair.kaist.ac.kr:/pub/gnu
  74.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  75.      AFRICA: ftp.sun.ac.za:/pub/gnu
  76.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  77.      EUROPE: irisa.irisa.fr:/pub/gnu, grasp1.univ-lyon1.fr:pub/gnu,
  78.           ftp.mcc.ac.uk, unix.hensa.ac.uk:/pub/uunet/systems/gnu,
  79.           src.doc.ic.ac.uk:/gnu, ftp.win.tue.nl, ugle.unit.no, ftp.denet.dk,
  80.           ftp.informatik.rwth-aachen.de:/pub/gnu, ftp.informatik.tu-muenchen.de,
  81.           ftp.eunet.ch, nic.switch.ch:/mirror/gnu, nic.funet.fi:/pub/gnu,
  82.           isy.liu.se, ftp.stacken.kth.se, ftp.luth.se:/pub/unix/gnu, archive.eu.net
  83.      CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  84.      USA: wuarchive.wustl.edu:/mirrors/gnu, labrea.stanford.edu,
  85.           ftp.kpc.com:/pub/mirror/gnu, ftp.cs.widener.edu, uxc.cso.uiuc.edu,
  86.           col.hp.com:/mirrors/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  87.           gatekeeper.dec.com:/pub/GNU, ftp.uu.net:/systems/gnu
  88.  
  89.    The "official site" is prep.ai.mit.edu, but your transfer will
  90. probably go faster if you use one of the above machines.
  91.  
  92.    Most GNU utilities are compressed with "gzip", the GNU compression
  93. utility.  All GNU archive sites should have a copy of this program,
  94. which you will need to uncompress the distributions.
  95.  
  96.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  97. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  98. Ohio State University.  You pay for the long-distance call to OSU; the
  99. price isn't too bad on weekends at 9600 bps.  Send mail to
  100. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  101.  
  102.    OSU lines are often busy.  If you're in the USA, and are willing to
  103. spend more money, you can get sources via UUCP from UUNET using their
  104. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  105. You will be billed $0.50/minute by your phone company.
  106.  
  107.    Don't forget to retrieve libg++ as well!
  108.  
  109.  
  110. Getting gcc/g++ for the HP Precision Architecture
  111. =================================================
  112.  
  113.    If you use the HP Precision Architecture (HP-9000/7xx and
  114. HP-9000/8xx) and you want to use debugging, you'll need to grab a
  115. special version of GAS from the University of Utah, site
  116. jaguar.cs.utah.edu.  Look in the `/dist' directory for gas-2.2.u7.  A
  117. non-standard debug format is used, since until recently HP considered
  118. their debug format a trade secret.  Thanks to the work of lots of good
  119. folks both inside and outside HP, the company has seen the error of its
  120. ways and has now released the required information.  The team at the
  121. University of Utah now has code that understands the native HP format.
  122. For now, the GNU debugger, GDB, understands the debug format produced
  123. by this version of GAS, but not the format produced by HP's compilers.
  124. However, another there is another version of GDB avaiable from this site
  125. that understands the debug format produced by the HP C compiler (but no
  126. version that understands both, unfortunately).
  127.  
  128.    Some enhancements for the HP that haven't been integrated back into
  129. the official GCC are available from the same site in version
  130. gcc-2.5.8.u8.  The site also has GDB (4.12.u3), GAS (2.2.u7), and
  131. libg++ (2.5.3.u3).  The libg++ version is actually the same as the FSF
  132. 2.5.3.
  133.  
  134.    I recommend that HP users use the Utah versions of the tools (see
  135. above).  At present, the Utah compiler, assembler, binutils, and
  136. debugger *must* be used as a complete set; they won't work with the
  137. generic FSF versions.  This will change in the future once the Utah
  138. changes have been merged back into the main FSF distributions.
  139.  
  140.    HP GNU users can also find useful stuff on the site geod.emr.ca in
  141. the `/pub/GNU-HP' directory.
  142.  
  143.  
  144. Getting gcc/g++ binaries for Solaris 2.x
  145. ========================================
  146.  
  147.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  148.  
  149.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  150. Solaris.  As a rule, these binaries are not updated as often as the
  151. sources are, so if you want the very latest version of gcc/g++, you may
  152. need to grab and install binaries for an older version and use it to
  153. bootstrap the latest version from source.
  154.  
  155.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  156. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  157. Solaris on Intel 386/486 machines.  There are also binaries for "gzip",
  158. the GNU compression utility, which you'll need for uncompressing the
  159. binary distribution.
  160.  
  161.  
  162. How do I get a copy of g++ for (some other platform)?
  163. =====================================================
  164.  
  165.    The standard gcc/g++ distribution includes VMS support.  Since the
  166. FSF people don't use VMS, it's likely to be somewhat less solid than
  167. the Unix version.  Precompiled copies of g++ and libg++ in
  168. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  169. See also the site ftp.stacken.kth.se (in Sweden), directory
  170. /pub/GNU-VMS/contrib, which has gcc-2.5.8 and libg++-2.5.3.
  171.  
  172.    DJ Delorie has ported gcc/g++ to MS-DOS; this port is popularly
  173. known as "DJGPP" (the P's stand for "plus").  It can be found on many
  174. FTP archive sites; its "home" is on oak.oakland.edu, directory
  175. `~ftp/pub/msdos/djgpp'.
  176.  
  177.    The latest version of DJGPP is 1.11.maint2.  This version runs under
  178. Windows 3.x.  It is a port of gcc 2.5.7.
  179.  
  180.    FSF sells floppies with DJGPP on them; see above for ordering
  181. software from the FSF.
  182.  
  183.    For information on Amiga ports of gcc/g++, retrieve the file
  184. `/pub/gnu/MicrosPorts/Amiga' from prep.ai.mit.edu, or write to Markus
  185. M. Wild <wild@nessie.cs.id.ethz.ch>, who I hope won't be too upset that
  186. I mentioned his name here.
  187.  
  188.    A port of gcc to the Atari ST can be found on the site
  189. "atari.archive.umich.edu", under `/atari/Gnustuff/Tos', along with many
  190. other GNU programs.  This version is usually the same as the latest FSF
  191. release.  See the "Software FAQ" for the Usenet group
  192. "comp.sys.atari.st" for more information.
  193.  
  194.    There are two different ports of gcc to OS/2, the so-called EMX
  195. port, and a port called "gcc/2".  The EMX port's C library attempts to
  196. provide a Unix-like environment; gcc/2 uses a rather buggy port of the
  197. BSD libc.  For more information ask around on
  198. "comp.os.os2.programmer.misc".  gcc/2, together with other GNUware for
  199. OS/2, can be obtained by FTP from
  200.  
  201.      ftp-os2.cdrom.com(192.153.46.2) in /pub/os2/2_x/unix/gnu
  202.      ftp-os2.nmsu.edu (128.123.35.151) in /pub/os2/2_x/unix/gnu
  203.      luga.latrobe.edu.au (131.172.2.2) in /pub/os2/2_x/unix/gnu
  204.  
  205.    The current maintainer of the gcc/2 port is Colin Jensen (Michael
  206. Johnson did the original port).  His address is cjensen@netcom.com.
  207.  
  208.    Eberhard Mattes did the EMX port.  His address is
  209. mattes@azu.informatik.uni-stuttgart.de.
  210.  
  211.    Because the legal policies of Apple threaten the long-term goals of
  212. FSF, as well as the concept of free software, no support will be lent to
  213. efforts to port GNU software to Macintosh or other Apple hardware.
  214.  
  215.  
  216. But I can only find g++-1.42!
  217. =============================
  218.  
  219.    "I keep hearing people talking about g++ 2.5.8 (or some other number
  220. starting with 2), but the latest version I can find is g++ 1.42.  Where
  221. is it?"
  222.  
  223.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  224. a single distribution called gcc.  If you get gcc you already have g++.
  225. The standard installation procedure for any gcc version 2 compiler will
  226. install the C++ compiler as well.
  227.  
  228.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  229. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  230.  
  231.  
  232. What is the latest version of gcc, g++, and libg++?
  233. ===================================================
  234.  
  235.    The latest "2.x" version of gcc/g++ is 2.5.8, released January 23,
  236. 1994.  The latest version of libg++ is 2.5.3, released December 21,
  237. 1993.  Don't use 2.5.x, with x less than 5, for C++ code; there were
  238. some serious bugs that didn't have easy workarounds.
  239.  
  240.    For some non-Unix platforms, the latest port of gcc may be an earlier
  241. version (2.4.5, say).  You'll need to use a version of libg++ that has
  242. the same first two digits as the compiler version, e.g. use libg++ 2.4
  243. with gcc version 2.4.5.
  244.  
  245.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  246. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  247. programs, I recommend against using g++ 1.x except in special
  248. circumstances.
  249.  
  250.  
  251. Installation Issues and Problems
  252. ********************************
  253.  
  254.  
  255. I can't build g++ 1.x.y with gcc-2.x.y!
  256. =======================================
  257.  
  258.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  259. I'm having major problems.  What's going on?"
  260.  
  261.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  262. installation instructions for g++ version 1 leave a lot to be desired,
  263. unfortunately, and I would recommend that, unless you have a special
  264. reason for needing the 1.x compiler, that C++ users use the latest
  265. g++-2.x version, as it is the version that is being actively maintained.
  266.  
  267.    There is no template support in g++-1.x, and it is generally much
  268. further away from the ANSI draft standard than g++-2.x is.
  269.  
  270.  
  271. OK, I've obtained gcc; what else do I need?
  272. ===========================================
  273.  
  274.    First off, you'll want libg++ as you can do almost nothing without it
  275. (unless you replace it with some other class library).
  276.  
  277.    Second, depending on your platform, you may need "gas", the GNU
  278. assembler, or the GNU linker (see next question).
  279.  
  280.    Finally, while it is not required, you'll almost certainly want the
  281. GNU debugger, gdb.  The latest version is 4.12, released Feb. 3, 1994.
  282. Other debuggers (like dbx, for example) will normally not be able to
  283. understand at least some of the debug information produced by g++.
  284.  
  285.  
  286. Should I use the GNU linker, or should I use "collect"?
  287. =======================================================
  288.  
  289.    First off, for novices: special measures must be taken with C++ to
  290. arrange for the calling of constructors for global or static objects
  291. before the execution of your program, and for the calling of
  292. destructors at the end.  (Exception: System VR3 and System VR4 linkers
  293. support user-defined segments; g++ on these systems requires neither
  294. the GNU linker nor collect.  So if you have such a system, the answer
  295. is that you don't need either one).
  296.  
  297.    If you have experience with AT&T's "cfront", this function is
  298. performed there by programs named "patch" or "munch".  With GNU C++, it
  299. is performed either by the GNU linker or by a program known as
  300. "collect".  The collect program is part of the gcc-2.x distribution;
  301. you can obtain the GNU linker separately as part of the "binutils"
  302. package.  The latest version of binutils is 2.3, released Nov. 11, 1993.
  303.  
  304.    (To be technical, it's "collect2"; there were originally several
  305. alternative versions of collect, and this is the one that survived).
  306.  
  307.    There are advantages and disadvantages to either choice.
  308.  
  309.    Advantages of the GNU linker:
  310.  
  311.    It's faster than using collect - collect basically runs the standard
  312. Unix linker on your program twice, inserting some extra code after the
  313. first pass to call the constructors.  This is a sizable time penalty
  314. for large programs.  The GNU linker does not require this extra pass.
  315.  
  316.    GNU ld reports undefined symbols using their true names, not the
  317. mangled names.
  318.  
  319.    If there are undefined symbols, GNU ld reports which object file(s)
  320. refer to the undefined symbol(s).
  321.  
  322.    As of binutils version 2.2, on systems that use the so-called "a.out"
  323. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  324. the debug symbol table considerably, which in at least some cases may
  325. make up, in disk space, for its inability to use shared libraries.
  326.  
  327.    Advantages of collect:
  328.  
  329.    If your native linker supports shared libraries, you can use shared
  330. libraries with collect.  The GNU linker does not (yet) support shared
  331. libraries.
  332.  
  333.    Note: using existing shared libraries (X and libc, for example) works
  334. very nicely; generating shared libraries from g++-compiled code is
  335. another matter, generally requiring OS-dependent tricks if it is
  336. possible at all.
  337.  
  338.    Ron Guilmette has written a set of patches for the g++ compiler that
  339. will permit people using g++ on SVr4 systems to build ELF format shared
  340. libraries.  Contact <rfg@netcom.com> for further information.
  341.  
  342.    The GNU linker has not been ported to as many platforms as g++ has,
  343. so you may be forced to use collect.
  344.  
  345.    If you use collect, you don't need to get something extra and figure
  346. out how to install it; the standard gcc installation procedure will do
  347. it for you.
  348.  
  349.    In conclusion, I don't see a clear win for either alternative at this
  350. point.  Take your pick.
  351.  
  352.  
  353. Should I use the GNU assembler, or my vendor's assembler?
  354. =========================================================
  355.  
  356.    This depends on your platform and your decision about the GNU
  357. linker.  For most platforms, you'll need to use gas if you use the GNU
  358. linker.  For some platforms, you have no choice; check the gcc
  359. installation notes to see whether you must use gas.  But you can
  360. usually use the vendor's assembler if you don't use the GNU linker.
  361.  
  362.    The GNU assembler assembles faster than many native assemblers;
  363. however, on many platforms it cannot support the local debugging format.
  364.  
  365.    If you want to build shared libraries from gcc/g++ output and you
  366. are on a Sun, you must *not* use GNU as, as it cannot do
  367. position-independent code correctly yet.
  368.  
  369.  
  370. Should I use the GNU C library?
  371. ===============================
  372.  
  373.    At this point in time, no.  The GNU C library is still very young,
  374. and libg++ still conflicts with it in some places.  Use your native C
  375. library unless you know a lot about the gory details of libg++ and
  376. gnu-libc.  This will probably change in the future.
  377.  
  378.  
  379. Global constructors aren't being called
  380. =======================================
  381.  
  382.    "I've installed gcc and it almost works, but constructors and
  383. destructors for global objects and objects at file scope aren't being
  384. called.  What did I do wrong?"
  385.  
  386.    It appears that you are running on a platform that requires you to
  387. install either "collect2" or the GNU linker, and you have done neither.
  388. For more information, see the section discussing the GNU linker (*Note
  389. use GNU linker?::).
  390.  
  391.  
  392. Strange assembler errors when linking C++ programs
  393. ==================================================
  394.  
  395.    "I've installed gcc and it seemed to go OK, but when I attempt to
  396. link any C++ program, I'm getting strange errors from the assembler!
  397. How can that be?"
  398.  
  399.    The messages in question might look something like
  400.  
  401.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  402.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  403.  
  404.    (on a Sun, different on other platforms).  The important thing is
  405. that the errors come out at the link step, *not* when a C++ file is
  406. being compiled.
  407.  
  408.    Here's what's going on: the collect2 program uses the Unix "nm"
  409. program to obtain a list of symbols for the global constructors and
  410. destructors, and it builds a little assembly language module that will
  411. permit them all to be called.  If you're seeing this symptom, you have
  412. an old version of GNU nm somewhere on your path.  This old version
  413. prints out symbol names in a format that the collect2 program does not
  414. expect, so bad assembly code is generated.
  415.  
  416.    The solution is either to remove the old version of GNU nm from your
  417. path (and that of everyone else who uses g++), or to install a newer
  418. version (it is part of the GNU "binutils" package).  Recent versions of
  419. GNU nm do not have this problem.
  420.  
  421.  
  422. Problems building libg++ on 386/486
  423. ===================================
  424.  
  425.    Attempts to install libg++ on 386 or 486 systems running ports of
  426. SVR4 have problems because of bugs in debugging support on that
  427. platform.  Briefly, debugging does not currently work right yet for
  428. C++.  You should be able to build the library successfully by deleting
  429. the `-g' flag from the Makefiles (this should no longer be necessary
  430. with gcc 2.4.x although debugging still doesn't work).
  431.  
  432.    See the section entitled "Debugging on SVR4 systems."
  433.  
  434.  
  435. Other problems building libg++
  436. ==============================
  437.  
  438.    "I am having trouble building libg++.  Help!"
  439.  
  440.    On some platforms (for example, Ultrix), you may see errors
  441. complaining about being unable to open dummy.o.  On other platforms
  442. (for example, SunOS), you may see problems having to do with the type
  443. of size_t.  The fix for these problems is to make libg++ by saying
  444. "make CC=gcc".  According to Per Bothner, it should no longer be
  445. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  446.  
  447.    "I built and installed libg++, but g++ can't find it.  Help!"
  448.  
  449.    The string given to `configure' that identifies your system must be
  450. the same when you install libg++ as it was when you installed gcc.
  451. Also, if you used the `--prefix' option to install gcc somewhere other
  452. than `/usr/local', you must use the same value for `--prefix' when
  453. installing libg++, or else g++ will not be able to find g++.
  454.  
  455.  
  456. But I'm *still* having problems with `size_t'!
  457. ==============================================
  458.  
  459.    "I did all that, and I'm *still* having problems with disagreeing
  460. definitions of size_t, SIZE_TYPE, and the type of functions like
  461. `strlen'."
  462.  
  463.    The problem may be that you have an old version of `_G_config.h'
  464. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  465. platform-specific, is inserted into a different directory; most include
  466. files are in `$prefix/lib/g++-include', but this file now lives in
  467. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  468. there is an old copy of `_G_config.h' left around, remove it, otherwise
  469. g++ will find the old one first.
  470.  
  471.  
  472. Do I need to rebuild libg++ to go with my new g++?
  473. ==================================================
  474.  
  475.    "After I upgraded g++ to the latest version, I'm seeing undefined
  476. symbols."
  477.  
  478.    or
  479.  
  480.    "If I upgrade to a new version of g++, do I need to reinstall
  481. libg++?"
  482.  
  483.    This depends; as a rule, some upgrades will require rebuilding libg++
  484. and others will not.  Both versions 2.3.3 and 2.4.0 introduced some
  485. incompatibilities with previous versions.  For 2.3.3, the name mangling
  486. of certain virtual table names changed, which introduced an
  487. incompatiblity.  For 2.4.0, the type of "size_t" changed on Suns from
  488. int (as declared by the include files provided by Sun) to unsigned long
  489. (the ANSI C and draft ANSI C++ standards declare that size_t must be
  490. unsigned, and the GCC maintainers are now correcting this "bug").
  491.  
  492.    With version 2.5 of g++ and libg++, major changes were made in the
  493. way that prototypes are provided for system functions.  Before, libg++
  494. provided prototypes for such functions in the g++-include directory.
  495. As of 2.5, gcc creates fixed headers suitable for both C and C++ as part
  496. of its installation process.  You definitely need to install a new
  497. libg++ to go with a 2.5.x release of g++.
  498.  
  499.    As a rule, the first two digits of your g++ and libg++ should be the
  500. same.
  501.  
  502.  
  503. User Problems
  504. *************
  505.  
  506.  
  507. gcc 2.5.x broke my code!  Changes in function overloading
  508. =========================================================
  509.  
  510.    "I have a program that worked just fine with older g++ versions, but
  511. as of version 2.5.x it doesn't work anymore.  Help!"
  512.  
  513.    While it's always possible that a new bug has been introduced into
  514. the compiler, it's also possible that you have been relying on bugs in
  515. older versions of g++.  For example, version 2.5.0 was the first
  516. version of g++ to correctly implement the "hiding rule."  That is, if
  517. you have an overloaded function in a base class, and in a derived class
  518. you redefine one of the names, the other names are effectively "hidden".
  519. *All* the names from the baseclass need to be redefined in the derived
  520. class.  See section 13.1 of the ARM: "A function member of a derived
  521. class is *not* in the same scope as a function member of the same name
  522. in a base class".
  523.  
  524.    Here's an example that is handled incorrectly by g++ versions before
  525. 2.5.0 and correctly by newer versions:
  526.  
  527.      class Base {
  528.      public:
  529.          void foo(int);
  530.      };
  531.      
  532.      class Derived : public Base {
  533.      public:
  534.          void foo(double);  // *note that Base::foo(int) is hidden*
  535.      };
  536.      
  537.      main() {
  538.          Derived d;
  539.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  540.      }
  541.  
  542.  
  543. Where can I find a demangler?
  544. =============================
  545.  
  546.    A g++-compatible demangler named `c++filt' can be found in the
  547. `binutils' distribution.  This distribution (which also contains the
  548. GNU linker) can be found at any GNU archive site.
  549.  
  550.  
  551. Where can I find a version of etags for C++?
  552. ============================================
  553.  
  554.    The libg++ distribution contains a version of etags that works for
  555. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  556. install libg++, but you can cd to that directory and type
  557.  
  558.      make etags
  559.  
  560.    after you've installed libg++.
  561.  
  562.  
  563. Linker reports undefined symbols for static data members
  564. ========================================================
  565.  
  566.    "g++ reports undefined symbols for all my static data members when I
  567. link, even though the program works correctly for compiler XYZ.  What's
  568. going on?"
  569.  
  570.    The problem is almost certainly that you don't give definitions for
  571. your static data members.  If you have
  572.  
  573.      class Foo {
  574.          ...
  575.          void method();
  576.          static int bar;
  577.      };
  578.  
  579.    you have only declared that there is an int named Foo::bar and a
  580. member function named Foo::method that is defined somewhere.  You still
  581. need to defined BOTH method() and bar in some source file.  According
  582. to the draft ANSI standard, you must supply an initializer, such as
  583.  
  584.      int Foo::bar = 0;
  585.  
  586. in one (and only one) source file.
  587.  
  588.  
  589. g++ won't accept the placement new syntax.
  590. ==========================================
  591.  
  592.    "I have a program that uses the "placement syntax" of operator new,
  593. e.g.
  594.  
  595.         new (somewhere) T;
  596.  
  597. and g++ won't accept it."
  598.  
  599.    Up until version 2.3.1, g++ accepted an alternate form of the
  600. placement syntax, for historical reasons; use
  601.  
  602.         new {somewhere} T;
  603.  
  604. if you are using g++-2.2.2 or older.
  605.  
  606.    As of 2.3.1, g++ finally fixed this, using the standard ARM syntax
  607. for "placement new".  A few remaining glitches were fixed in 2.3.2.  The
  608. only remaining problem is with declarators for pointers to functions;
  609.  
  610.      new (void (*)(int));  // confuses gcc 2.3.2
  611.      new (a) (void (*)(int)); // ditto
  612.  
  613.    These can be worked around with a typedef:
  614.  
  615.      typedef void (*fun)(int);
  616.      new fun;
  617.      new (a) fun;
  618.  
  619.  
  620. Overloaded increment (`++') and decrement (`--') operators
  621. ==========================================================
  622.  
  623.    "g++ doesn't seem to distinguish the prefix and postfix forms of
  624. `operator++'.  What gives?"
  625.  
  626.    This is a relatively new feature in the C++ language.  The solution
  627. is to upgrade your compiler; distinguishing the prefix and postfix cases
  628. of `operator++' and `operator--' was first implemented in g++ version
  629. 2.4.1.
  630.  
  631.    For backward compatibility, if a class declares a prefix version of
  632. `operator++' (or `operator--') but no postfix version, and code
  633. attempts to use `++' (or `--') as a postfix operator, g++ will use the
  634. prefix version (unless the `-pedantic' flag is set).  This feature is
  635. to avoid breaking old code.
  636.  
  637.  
  638. I think I have found a bug in g++.
  639. ==================================
  640.  
  641.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  642. and who should I tell?"
  643.  
  644.    First, see the excellent section on bugs and bug reports in the gcc
  645. manual (which is included in the gcc distribution).  As a short summary
  646. of that section: if the compiler gets a fatal signal, for any input,
  647. it's a bug (newer versions of g++ will ask you to send in a bug report
  648. when they detect an error in themselves).  Same thing for producing
  649. invalid assembly code.
  650.  
  651.    When you report a bug, make sure to describe your platform (the type
  652. of computer, and the version of the operating system it is running) and
  653. the version of the compiler that you are running.  Also provide enough
  654. code so that the g++ maintainers can duplicate your bug.
  655.  
  656.    I will add some extra notes that are C++-specific, since the notes
  657. from the gcc documentation are generally C-specific.
  658.  
  659.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  660. also post to gnu.g++.bug, but it's better to use mail, particularly if
  661. you have any doubt as to whether your news software generates correct
  662. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  663.  
  664.    If your bug involves libg++ rather than the compiler, mail to
  665. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  666. guessed wrong, the maintainers will forward it to the other list.
  667.  
  668.    Second, if your program does one thing, and you think it should do
  669. something else, it is best to consult a good reference if in doubt.  The
  670. standard reference is "The Annotated C++ Reference Manual", by Ellis and
  671. Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is what they're
  672. talking about on the net when they refer to "the ARM".
  673.  
  674.    The reference manual, without annotations, also appears in
  675. Stroustrup's "The C++ Programming Language, Second Edition" (copyright
  676. 1991, ISBN #0-201-53992-6).  Both books are published by Addison-Wesley.
  677.  
  678.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  679. is NOT the standard for the language.
  680.  
  681.  
  682. Porting programs from other compilers to g++
  683. ============================================
  684.  
  685.    "I have a program that runs on <some other C++ compiler>, and I want
  686. to get it running under g++.  Is there anything I should watch out for?"
  687.  
  688.    First, see the questions on placement new syntax and static data
  689. members.
  690.  
  691.    Secondly, if the porting problem relates to the resolution of
  692. overloaded operators or functions, you might try the
  693. `-fansi-overloading' switch in g++ 2.5.0 or later.  This switch enables
  694. new code that attempts to match the ARM specification of overloaded
  695. argument resolution better.
  696.  
  697.    There are two other reasons why a program that worked under one
  698. compiler might fail under another: your program may depend on the order
  699. of evaluation of side effects in an expression, or it may depend on the
  700. lifetime of a temporary (you may be assuming that a temporary object
  701. "lives" longer than the standard guarantees).  As an example of the
  702. first:
  703.  
  704.      void func(int,int);
  705.      
  706.      int i = 3;
  707.      func(i++,i++);
  708.  
  709.    Novice programmers think that the increments will be evaluated in
  710. strict left-to-right order.  Neither C nor C++ guarantees this; the
  711. second increment might happen first, for example.  func might get 3,4,
  712. or it might get 4,3.
  713.  
  714.    The second problem often happens with classes like the libg++ String
  715. class.  Let's say I have
  716.  
  717.      String func1();
  718.      void func2(const char*);
  719.  
  720.    and I say
  721.  
  722.      func2(func1());
  723.  
  724.    because I know that class String has an "operator const char*".  So
  725. what really happens is
  726.  
  727.      func2(func1().convert());
  728.  
  729.    where I'm pretending I have a convert() method that is the same as
  730. the cast.  This is unsafe, because the temporary String object may be
  731. deleted after its last use (the call to the conversion function),
  732. leaving the pointer pointing to garbage, so by the time func2 is
  733. called, it gets an invalid argument.
  734.  
  735.    Both the cfront and the g++ behaviors are legal according to the ARM,
  736. but the powers that be have decided that compiler writers were given
  737. too much freedom here.  The ANSI C++ committee has now come to a
  738. resolution of the lifetime of temporaries problem: they specify that
  739. temporaries should be deleted at end-of-statement (and at a couple of
  740. other points).  This means that g++ now deletes temporaries too early,
  741. and cfront deletes temporaries too late.
  742.  
  743.    For now, the safe way to write such code is to give the temporary a
  744. name, which forces it to live until the end of the scope of the name.
  745. For example:
  746.  
  747.      String& tmp = func1();
  748.      func2(tmp);
  749.  
  750.    Finally, like all compilers (but especially C++ compilers, it seems),
  751. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  752. report (after checking the above issues).
  753.  
  754.  
  755. Why does g++ mangle names differently from other C++ compilers?
  756. ===============================================================
  757.  
  758.    See the answer to the next question.
  759.  
  760.  
  761. Why can't g++ code link with code from other C++ compilers?
  762. ===========================================================
  763.  
  764.    "Why can't I link g++-compiled programs against libraries compiled by
  765. some other C++ compiler?"
  766.  
  767.    Some people think that, if only the FSF and Cygnus Support folks
  768. would stop being stubborn and mangle names the same way that, say,
  769. cfront does, then any g++-compiled program would link successfully
  770. against any cfront-compiled library and vice versa.  Name mangling is
  771. the least of the problems.  Compilers differ as to how objects are laid
  772. out, how multiple inheritance is implemented, how virtual function
  773. calls are handled, and so on, so if the name mangling were made the
  774. same, your programs would link against libraries provided from other
  775. compilers but then crash when run.  For this reason, the ARM
  776. *encourages* compiler writers to make their name mangling different
  777. from that of other compilers for the same platform.  Incompatible
  778. libraries are then detected at link time, rather than at run time.
  779.  
  780.  
  781. What documentation exists for g++ 2.x?
  782. ======================================
  783.  
  784.    Relatively little.  While the gcc manual that comes with the
  785. distribution has some coverage of the C++ part of the compiler, it
  786. focuses mainly on the C compiler (though the information on the "back
  787. end" pertains to C++ as well).  Still, there is useful information on
  788. the command line options and the #pragma interface and #pragma
  789. implementation directives in the manual.  There is a Unix-style manual
  790. entry, "g++.1", in the gcc-2.x distribution; the information here is a
  791. subset of what is in the manual.
  792.  
  793.    You can buy a nicely printed and bound copy of this manual from the
  794. FSF; see above for ordering information.
  795.  
  796.    A draft of a document describing the g++ internals appears in the gcc
  797. distribution (called g++int.texi); it is still incomplete.
  798.  
  799.  
  800. What are the differences between g++ and the ARM specification of C++?
  801. ======================================================================
  802.  
  803.    The chief thing missing from g++ that is in the ARM is exceptions.
  804. There are bits and pieces of exception code present, but it is not
  805. presently usable.
  806.  
  807.    The template implementation is still new.  The implementation in
  808. 2.5.x represents a considerable improvement over that of previous
  809. releases, but it has a long way to go.  This continues to improve from
  810. release to release.
  811.  
  812.    g++ does not implement a separate pass to instantiate template
  813. functions and classes at this point; for this reason, it will not work,
  814. for the most part, to declare your template functions in one file and
  815. define them in another.  The compiler will need to see the entire
  816. definition of the function, and will generate a static copy of the
  817. function in each file in which it is used.  For 2.5.0, however, a new
  818. switch `-fexternal-templates' was added; this makes it possible to have
  819. only one globally visible copy of a given template expansion in your
  820. executable.  See the gcc manual for details.
  821.  
  822.    As of version 2.5.8, there are still a few limitations in the
  823. template implementation besides the above (thanks to Jason Merrill for
  824. this info):
  825.  
  826.   1. Static data member templates are not supported.
  827.  
  828.           template <class T> struct A {
  829.             static T t;
  830.           };
  831.           
  832.           template <class T> T A<T>::t = 0; // gets bogus error
  833.           int A<int>::t = 0;                // OK
  834.  
  835.   2. Template member names are not available when defining member
  836.      function templates.
  837.  
  838.           template <class T> struct A {
  839.             typedef T foo;
  840.             void f (foo);
  841.             void g (foo arg) { ... }; // this works
  842.           };
  843.           
  844.           template <class T> void A<T>::f (foo) { } // gets bogus error
  845.  
  846.   3. Templates are instantiated using the parser.  This results in two
  847.      problems:
  848.  
  849.      a) Class templates are instantiated in some situations where such
  850.      instantiation should not occur.
  851.  
  852.           template <class T> class A { };
  853.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  854.  
  855.      b) Function templates cannot be inlined at the site of their
  856.      instantiation.
  857.  
  858.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  859.           
  860.           void f () {
  861.             int i = min (1, 0);           // not inlined
  862.             int j = min (1, 0);           // inlined
  863.           }
  864.  
  865.   4. Member function templates are always instantiated when their
  866.      containing class is.  This is wrong.
  867.  
  868.    Some features that the ANSI/ISO standardization committee has voted
  869. in that don't appear in the ARM are supported, notably the `mutable'
  870. keyword, in version 2.5.x.
  871.  
  872.    As with any beta-test compiler, there are bugs.  You can help improve
  873. the compiler by submitting detailed bug reports.
  874.  
  875.    One of the weakest areas of g++ other than templates is the
  876. resolution of overloaded functions and operators in complex cases.  The
  877. usual symptom is that in a case where the ARM says that it is ambiguous
  878. which function should be chosen, g++ chooses one (often the first one
  879. declared).  This is usually not a problem when porting C++ code from
  880. other compilers to g++, but shows up as errors when code developed under
  881. g++ is ported to other compilers.
  882.  
  883.    As of 2.5.0, the overloading code has been rewritten.  For now, you
  884. must specify the option `-fansi-overloading' to get the new code, since
  885. there were some important users actually depending on g++'s incorrect
  886. resolution of ambiguities.  This switch should disappear in the future.
  887. If a program that compiled under previous g++ versions now reports that
  888. a use of an overloaded function is ambiguous, it is likely that the old
  889. g++ was letting you write buggy code and the new one is detecting the
  890. problem.  If in doubt, consult the ARM.
  891.  
  892.    [A full bug list would be very long indeed, so I won't put one here.
  893. I may add a list of frequently-reported bugs and "non-bugs" like the
  894. static class members issue mentioned above].
  895.  
  896.  
  897. Will g++ compile InterViews?  The NIH class library?
  898. ====================================================
  899.  
  900.    The NIH class library uses a non-portable, compiler-dependent hack
  901. to initialize itself, which makes life difficult for g++ users.  It
  902. will not work without modification, and I don't know what modifications
  903. are required or whether anyone has done them successfully.
  904.  
  905.    In short, it's not going to happen any time soon (previous FAQs
  906. referred to patches that a new NIHCL release would hopefully contain,
  907. but this hasn't happened).
  908.  
  909.    [ From Steinar Bang <steinarb@idt.unit.no>]
  910.  
  911.    InterViews 3.1 compiles and runs with gcc-2.3.3 and libg++-2.3,
  912. except that the "doc" application immediately dumps core when you try
  913. to run it.  There is also a small glitch with idraw.
  914.  
  915.    There is a patch for InterViews 3.1 from Johan Garpendahl
  916. <garp@isy.liu.se> available for FTP from site "ugle.unit.no".  It is in
  917. the file
  918.  
  919.    `/pub/X11/contrib/InterViews/g++/3.1-beta3-patch'.
  920.  
  921.    This fixes two things: the Doc coredump, and the pattern menu of
  922. idraw.  Read the instructions at the start of the file.
  923.  
  924.    I think that as of version 2.5.6, the standard g++ will compile the
  925. standard 3.1 InterViews completely successfully.  I'd appreciate a
  926. confirmation.
  927.  
  928.  
  929. Debugging on SVR4 systems
  930. =========================
  931.  
  932.    "When I use the `-g' flag on C++ code on a System V Release 4 system,
  933. I get lots of undefined symbols at link time.  Why?  Help!"
  934.  
  935.    Most systems based on System V Release 4 (except Solaris) encode
  936. symbolic debugging information in a format known as `DWARF'.
  937.  
  938.    Although the GNU C compiler already knows how to write out symbolic
  939. debugging information in the DWARF format, the GNU C++ compiler does
  940. not yet have this feature, nor is it likely to in the immediate future.
  941.  
  942.    Ron Guilmette has done a great deal of work to try to get the GNU
  943. C++ com- piler to produce DWARF format symbolic debugging information
  944. (for C++ code) but he gave up on the project because of a lack of
  945. funding and/or interest from the g++ user community.  If you have a
  946. strong desire to see this project completed, contact Ron at
  947. <rfg@netcom.com>.
  948.  
  949.  
  950. What are the rules for shipping code built with g++ and libg++?
  951. ***************************************************************
  952.  
  953.    "Is it is possible to distribute programs for profit that are created
  954. with g++ and use the g++ libraries?"
  955.  
  956.    I am not a lawyer, and this is not legal advice.  In any case, I have
  957. little interest in telling people how to violate the spirit of the GNU
  958. licenses without violating the letter.  This section tells you how to
  959. comply with the intention of the GNU licenses as best I understand them.
  960.  
  961.    The FSF has no objection to your making money.  Its only interest is
  962. that source code to their programs, and libraries, and to modified
  963. versions of their programs and libraries, is always available.
  964.  
  965.    The short answer is that you do not need to release the source to
  966. your program, but you can't just ship a stripped executable either,
  967. unless you use only the subset of libg++ that includes the iostreams
  968. classes (see discussion below).
  969.  
  970.    Compiling your code with a GNU compiler does not affect its
  971. copyright; it is still yours.  However, in order to ship code that
  972. links in a GNU library such as libg++ there are certain rules you must
  973. follow.  The rules are described in the file COPYING.LIB that
  974. accompanies gcc distributions; it is also included in the libg++
  975. distribution.  See that file for the exact rules.  The agreement is
  976. called the Library GNU Public License or LGPL.  It is much "looser"
  977. than the GNU Public License, or GPL, that covers must GNU programs.
  978.  
  979.    Here's the deal: let's say that you use some version of libg++,
  980. completely unchanged, in your software, and you want to ship only a
  981. binary form of your code.  You can do this, but there are several
  982. special requirements.  If you want to use libg++ but ship only object
  983. code for your code, you have to ship source for libg++ (or ensure
  984. somehow that your customer already has the source for the exact version
  985. you are using), and ship your application in linkable form.  You cannot
  986. forbid your customer from reverse-engineering or extending your program
  987. by exploiting its linkable form.
  988.  
  989.    Furthermore, if you modify libg++ itself, you must provide source
  990. for your modifications (making a derived class does not count as
  991. modifying the library - that is "a work that uses the library").
  992.  
  993.    For certain portions of libg++ that implement required parts of the
  994. C++ language (such as iostreams), the FSF has loosened the copyright
  995. requirement still more by adding the "special exception" clause, which
  996. reads as follows:
  997.  
  998.      As a special exception, if you link this library with files
  999.      compiled with GCC to produce an executable, this does not cause
  1000.      the resulting executable to be covered by the GNU General Public
  1001.      License.  This exception does not however invalidate any other
  1002.      reasons why the executable file might be covered by the GNU
  1003.      General Public License.
  1004.  
  1005.    If your only use of libg++ uses code with this exception, you may
  1006. ship stripped executables or license your executables under different
  1007. conditions without fear of violating an FSF copyright.  It is the intent
  1008. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1009. draft standard are developed, these will also be placed under this
  1010. "special exception" license.
  1011.  
  1012.    To avoid coming under the influence of the LGPL, you can link with
  1013. `-liostream' rather than `-lg++'.
  1014.  
  1015.  
  1016. Concept Index
  1017. *************
  1018.  
  1019. -- 
  1020. -- Joe Buck     <jbuck@synopsys.com>
  1021. Posting from but not speaking for Synopsys, Inc.
  1022. ***** Stamp out junk e-mail spamming!  If someone sends you a junk e-mail
  1023. ***** ad just because you posted in comp.foo, boycott their company.
  1024.  
  1025.